package com.suxin.http.response.handler;

import com.alibaba.nacos.common.utils.JacksonUtils;
import com.suxin.http.model.Header;
import com.suxin.http.model.HttpRestResult;
import com.suxin.http.response.HttpClientResponse;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;

/**
 * @author Tang
 * @classname ResultRestResponseHandler
 * @description [ RestResult ]
 * @date 2023/3/2 22:16
 */
public class ResultRestResponseHandler<T> extends AbstractResponseHandler<T>{
    @Override
    protected HttpRestResult<T> convertHandler(HttpClientResponse response, Type type) throws IOException {
        final InputStream body = response.getBody();
        final Header headers = response.getHeaders();
        final HttpRestResult<T> restResult = JacksonUtils.toObj(body, type);
        restResult.setHeader(headers);
        return restResult;
    }
}
